﻿#ifndef CameraNetWork_H
#define CameraNetWork_H

#include "camera.h"
#include "opencv2/opencv.hpp"
#include <QObject>
#include <QThread>

class CameraWorker : public QObject
{
    Q_OBJECT
public:
    explicit CameraWorker(QObject* parent =  nullptr);
    void init(void*cap);

signals:
    void sigWarning(QString msg);
    void sigCaptureFinished(cv::Mat);

public:
    void run();

private:
    cv::VideoCapture *m_cap = nullptr;
};


class CameraNetWork : public Camera
{
    Q_OBJECT
public:
    CameraNetWork(const std::string name);
    virtual ~CameraNetWork();
    // Camera interface
public slots:
    virtual void initialize() override;
    virtual void openCamera() override;
    virtual void startGrabbing() override;
    virtual void stopGrabbing() override;
    virtual void closeCamera() override;
    virtual void releaseCamera() override;

    virtual void triggerSoftware() override;
    virtual void setExposureTime(const std::string &camName, const FloatValue &value) override;
    virtual void setBrightness(const std::string &camName, const FloatValue &value) override;
    virtual void setWidth(const std::string &camName, const IntValue &width) override;
    virtual void setHeight(const std::string &camName, const IntValue &height) override;

    // Camera interface
public slots:
    virtual void preProcessImage(const ImageInfo &imgInfo) override;

public:
    virtual bool isColor(int pixelFormat) override;
    virtual bool isMono(int pixelFormat) override;


signals:
    void sigStart();
public slots:
    void onCaptureFinished(cv::Mat);
    void onWarnMessg(QString messg);
    //void onSaveParam(int exposeVal, int camerCapNum);

private:
    //int m_triggerMode;
    //int m_triggerSource;
    bool m_takePic;
    //bool m_singlePic;
    //int m_index;
    int m_capIndex;
    //int m_expose;
    int m_width;
    int m_height;

    cv::VideoCapture* m_cap;

    CameraWorker* m_worker;
    QThread *m_thread;
};

#endif // CameraNetWork_H
